package com.example.annealing.common.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.Data;

import java.util.List;

/**
 * 分页数据封装类
 *
 * @author Gene
 * @date 2019/4/19
 */
@Data
public class CommonPage<T> {
    private Long current;
    private Long size;
    private Long totalPage;
    private Long total;
    private List<T> list;

    /**
     * 将mybatis-plus分页后的list转为分页信息
     */
    public static <T> CommonPage<T> restPage(IPage<T> iPage) {
        CommonPage<T> result = new CommonPage<>();
        result.setTotalPage(iPage.getPages());
        result.setCurrent(iPage.getCurrent());
        result.setSize(iPage.getSize());
        result.setTotal(iPage.getTotal());
        result.setList(iPage.getRecords());
        return result;
    }
}
